package com.zjy.software.day14;

public class JoinTest {
    public static void main(String[] args) throws InterruptedException {
//        testJoinMethod();

        Runnable deamon=new Runnable() {
            @Override
            public void run() {
                System.out.println("JoinTest.run");
                int count=0;
                while (true){
                    count++;
                    System.out.println("守护线程"+count);
                    try {
                        Thread.sleep(500);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }

        };

        Thread thread=new Thread(deamon);
        //把当前线程设置成守护线程,当主线程退出时,哪怕子线程是死循环,那么子线程也会退出
        thread.setDaemon(true);
        thread.setName("DaemonThread");
        thread.start();
        System.out.println("thread = " + thread);
        Thread.sleep(10000);
    }

    private static void testJoinMethod() throws InterruptedException {
        Thread xi=new XiThread();
        xi.start();
        xi.join();

        Thread qie=new QieThread();
        qie.start();
        qie.join();

        Thread chao=new ChaoThread();
        chao.start();
        chao.join();
    }
}